package com.deram.ctin.serv.enter.impl;

import com.deram.ctin.common.bean.PageResult;
import com.deram.ctin.serv.enter.api.EnterInfoApi;
import com.deram.ctin.serv.enter.api.EnterMainUserApi;
import com.deram.ctin.serv.enter.entity.BaseUpdateInfo;
import com.deram.ctin.serv.enter.entity.EnterChangeLog;
import com.deram.ctin.serv.enter.entity.EnterInfo;
import com.deram.ctin.serv.enter.entity.EnterMainUser;
import com.deram.ctin.serv.enter.filter.EnterMainUserFilter;
import com.deram.ctin.serv.enter.service.EnterMainUserService;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: jtt
 * @Description:
 * @Date: 2017/9/13 13:54
 * @version: V1.0
 */
@RestController
public class EnterMainUserApiImpl implements EnterMainUserApi {

    @Autowired
    private EnterMainUserService enterMainUserService;

    @Autowired
    private EnterInfoApi enterInfoApi;

    @Override
    public List<EnterMainUser> list(@RequestBody EnterMainUserFilter param) {
        return enterMainUserService.list(param);
    }

    @Override
    public List<EnterInfo> searchByCode(@RequestBody EnterMainUserFilter filter) {
        List<EnterMainUser> users = enterMainUserService.searchByCode(filter);
        List<EnterInfo> info = Lists.newArrayList();
        for (EnterMainUser user:users) {
            info.add(enterInfoApi.findById(user.getEnterId()));
        }
        return info;
    }

    @Override
    public List<EnterMainUser> findByEnterInfo(@RequestParam("id") Long id) {
        return enterMainUserService.findByEnterInfo(id);
    }

    @Override
    public EnterMainUser save(@RequestBody EnterMainUser param) {
        return enterMainUserService.save(param);
    }

    @Override
    public void delete(Long id) {
        enterMainUserService.delete(id);
    }

    @Override
    public PageResult<EnterMainUser> search(@RequestBody EnterMainUserFilter filter, @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        return enterMainUserService.findByEnterInfo(filter,pageNo,pageSize);
    }


    @Override
    public void saveList(@RequestBody BaseUpdateInfo<EnterMainUser> updateInfo) {
        enterMainUserService.saveList(updateInfo);
    }
}
